package com.zst.rabbitmq.monitor.dto;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

public class ClusterNode {
    /** 节点名称 */
    private String name;
    /** 节点类型， ram或disc*/
    private String type;
    /** 是否运行中*/
    private Boolean running;
    /** 内存总量*/
    private Long memLimit;
    /** 已使用内存*/
    private Long memUsed;
    /** 文件描述符总量*/
    private Integer fdTotal;
    /** 已使用文件描述符数量*/
    private Integer fdUsed;
    /** 磁盘容量*/
    private Long diskLimit;
    /** 磁盘剩余空闲容量*/
    private Long diskFree;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public boolean getRunning() {
        return running;
    }

    public void setRunning(boolean running) {
        running = running;
    }

    public long getMemLimit() {
        return memLimit;
    }

    public void setMemLimit(long memLimit) {
        this.memLimit = memLimit;
    }

    public long getMemUsed() {
        return memUsed;
    }

    public void setMemUsed(long memUsed) {
        this.memUsed = memUsed;
    }

    public int getFdTotal() {
        return fdTotal;
    }

    public void setFdTotal(int fdTotal) {
        this.fdTotal = fdTotal;
    }

    public int getFdUsed() {
        return fdUsed;
    }

    public void setFdUsed(int fdUsed) {
        this.fdUsed = fdUsed;
    }

    public long getDiskLimit() {
        return diskLimit;
    }

    public void setDiskLimit(long diskLimit) {
        this.diskLimit = diskLimit;
    }

    public long getDiskFree() {
        return diskFree;
    }

    public void setDiskFree(long diskFree) {
        this.diskFree = diskFree;
    }

    public static ClusterNode map(String json) {
        if (StringUtils.isEmpty(json)) {
            return null;
        }

        ClusterNode dto = new ClusterNode();
        JSONObject jo = JSONObject.parseObject(json);

        dto.setName(jo.getString("name"));
        dto.setType(jo.getString("type"));
        dto.setRunning(jo.getBoolean("running"));
        dto.setMemUsed(jo.getLong("mem_used"));
        dto.setMemLimit(jo.getLong("mem_limit"));
        dto.setDiskLimit(jo.getLong("disk_free_limit"));
        dto.setDiskFree(jo.getLong("disk_free"));
        dto.setFdTotal(jo.getInteger("fd_total"));
        dto.setFdUsed(jo.getInteger("fd_used"));

        return dto;
    }

    @Override
    public String toString() {
        return "ClusterNode{" +
                "name='" + name + '\'' +
                ", type='" + type + '\'' +
                ", running=" + running +
                ", memLimit=" + memLimit +
                ", memUsed=" + memUsed +
                ", fdTotal=" + fdTotal +
                ", fdUsed=" + fdUsed +
                ", diskLimit=" + diskLimit +
                ", diskFree=" + diskFree +
                '}';
    }
}
